from django.http import HttpResponse
from rest_framework.views import APIView

from toolbox import etag_json, get_client_ip, get_scan_type, resolve_url

from .models import F


def show_ip(request):
    ip = get_client_ip(request)
    return HttpResponse(ip)


def show_agent(request):
    client = get_scan_type(request)
    return HttpResponse(client)


def show_url(request, foo):
    url = resolve_url(request, foo, "show_url", "demo_app")
    return HttpResponse(url)


class ETagView(APIView):
    @staticmethod
    def get(request, *args, **kwargs):
        data = [{"id": i.id, "a": i.a} for i in F.objects.all()]
        return etag_json(data, request)
